package com.len.utils;

/**
 * @Author: xudeli
 * @Description: 按字典顺序比较字符串
 * @CreateDate: 2018/3/25 16:44
 **/
public class ComparableUtils {

    public static Comparable findMaxStr(Comparable[] arr) {
        int maxIndex = 0;
        for (int i = 1; i < arr.length; i++) {
            if (arr[i].compareTo(arr[maxIndex]) > 0) {
                maxIndex = i;
            }
        }
        return arr[maxIndex];
    }

    public static int comparableStr(Comparable[] arr) {
        int maxIndex = 0;
        int count = 0;
        for (int i = 1; i < arr.length; i++) {
            if (arr[i].compareTo(arr[maxIndex]) == 0) {
                count++;
            } else if (arr[i].compareTo(arr[maxIndex]) >= 0) {
                maxIndex = i;
            }
        }
        return count;
    }
}
